import 'package:flutter/material.dart';

import 'package:wheel_of_fortune/utils/utils.dart';

class BgButton extends StatelessWidget {
  final color;
  final title;
  final onTap;
  final height;
  final width;
  const BgButton(
      {this.title = '',
      this.width,
      this.height = 30.0,
      this.color = deepYellowColor,
      this.onTap,
      Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: this.width,
      height: this.height,
      child: RaisedButton(
        onPressed: this.onTap,
        elevation: 0,
        color: this.color,
        child: Text(
          this.title,
          style: TextStyle(
            fontFamily: 'Avenir Next LT Pro',
            fontSize: 14.0,
            fontWeight: FontWeight.bold,
            color: whiteColor,
          ),
        ),
        disabledColor: grey6EColor,
        shape: RoundedRectangleBorder(
          side: BorderSide(
            // 保留原来的边框样式
            width: 0.5,
            color: this.onTap == null ? grey6EColor : this.color,
            style: BorderStyle.solid,
          ),
          borderRadius: BorderRadius.all(Radius.circular(15.0)),
        ),
      ),
    );
  }
}

class BorderButton extends StatelessWidget {
  final color;
  final title;
  final onTap;
  const BorderButton(
      {this.title = '', this.color = deepYellowColor, this.onTap, Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 30,
      child: RaisedButton(
        onPressed: this.onTap,
        elevation: 0,
        color: whiteColor,
        child: Text(
          this.title,
          style: TextStyle(
            fontFamily: 'Avenir Next LT Pro',
            fontSize: 14.0,
            fontWeight: FontWeight.bold,
            color: this.color,
          ),
        ),
        shape: RoundedRectangleBorder(
          side: BorderSide(
            // 保留原来的边框样式
            width: 0.5,
            color: this.color,
            style: BorderStyle.solid,
          ),
          borderRadius: BorderRadius.all(Radius.circular(15.0)),
        ),
      ),
    );
  }
}

class ColorButton extends StatelessWidget {
  final onTap;
  final title;
  final width;
  final height;
  final bgColor;
  final color;
  final fontSize;
  const ColorButton(
      {this.onTap,
      this.title,
      this.width = 61.0,
      this.height = 20.0,
      this.color,
      this.bgColor,
      this.fontSize = 10.0,
      Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: InkWell(
        child: Container(
          height: this.height,
          width: this.width,
          alignment: Alignment.center,
          decoration: BoxDecoration(
            color: this.bgColor ?? deepYellowColor,
            borderRadius: BorderRadius.circular(this.height / 2.0),
          ),
          child: Text(
            this.title ?? '',
            textAlign: TextAlign.center,
            style: TextStyle(
                color: this.color ?? whiteColor,
                fontSize: this.fontSize,
                fontFamily: 'Avenir Next LT Pro'),
          ),
        ),
        onTap: this.onTap,
      ),
    );
  }
}

class CandyBalanceButton extends StatelessWidget {
  final onTap;
  final count;
  const CandyBalanceButton({this.onTap, this.count = 0, Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    double offset = 0;
    if (this.count >= 100 && this.count < 1000) {
      offset = 7;
    } else if (this.count >= 1000 && this.count < 10000) {
      offset = 14;
    } else if (this.count >= 10000) {
      offset = 21;
    } else if (this.count >= 10 && this.count < 100) {
      offset = 3;
    }

    return Container(
      child: InkWell(
        child: Container(
            height: 35,
            width: 110 + (2 * offset),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(10),
              gradient: const LinearGradient(
                  colors: [Color(0xFFEE82CD), Color(0xFF07CDFE)]),
            ),
            child: Row(
              // mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(
                  width: 14,
                ),
                Text(
                  'Candy\nBalance',
                  textAlign: TextAlign.left,
                  style: TextStyle(
                      color: whiteColor,
                      fontSize: 10,
                      fontFamily: 'Avenir Next LT Pro',
                      fontWeight: FontWeight.bold),
                ),
                Spacer(),
                Text(
                  '${this.count}',
                  textAlign: TextAlign.left,
                  style: TextStyle(
                      color: whiteColor,
                      fontSize: 24,
                      fontFamily: 'Avenir Next LT Pro',
                      fontWeight: FontWeight.bold),
                ),
                SizedBox(
                  width: 14,
                ),
              ],
            )),
        onTap: this.onTap,
      ),
    );
  }
}
